<template>
    <div>
        <el-table ref="multipleTable" :data="tableData" tooltip-effect="dark"  style="width: 100%">
            <el-table-column prop="road" label="巷道" ></el-table-column>
            <el-table-column prop="roadName" label="巷道名称" ></el-table-column>
            <el-table-column prop="status" label="状态" ></el-table-column>
            <el-table-column label="操作" >
                <template slot-scope="scope">
                    <el-button @click="start(scope.row)" type="text" size="small">启用</el-button>
                    <el-button @click="stop(scope.row)" type="text" size="small">禁用</el-button>
                </template>
            </el-table-column>
        </el-table>
    </div>
</template>

<script>
import request from "@/utils/request.js";
export default {
    data() {
        return {
            tableData:[]
        }
    },
    methods: {
        start(row){
            row.statusCode = "1";
            request.post("/systemRoadController/updateRoadStatus",row).then((res)=>{
                console.log("res",res);
                if(res.data.retCode=="200"){
                    this.$message({ type: 'success', message: '操作成功!' });
                }else{
                    this.$message({ type: 'error', message: '操作失败!' });
                }
                this.doQuery();
            })
        },
        stop(row){
            //updateRoadStatus
            this.$confirm('禁用巷道后，接收将无法喊此箱子，请确认是否要此操作!?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    row.statusCode = "0";
                    request.post("/systemRoadController/updateRoadStatus",row).then((res)=>{
                        if(res.data.retCode=="200"){
                            this.$message({ type: 'success', message: '操作成功!' });
                        }else{
                            this.$message({ type: 'error', message: '操作失败!' });
                        }
                        this.doQuery();
                    })
                }).catch(() => {});
        },
        doQuery(){
            request.post("/systemRoadController/queryRoad",{}).then((res)=>{
                console.log("res",res);
                this.tableData = res.data;
            });
        }
    },
    mounted(){
        this.doQuery();
    }
}
</script>